import type { QmsInspectionTerminal, QmsInspectionTerminalItem } from "@/pages/qms/terminal/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //名称
  name?: string;
  //设备IP
  ip?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: QmsInspectionTerminal[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/qms/terminal/pageList",
    data
});
const getInfo = (id: React.Key): Promise<QmsInspectionTerminal> =>
  apiClient.get({
    url: `/qms/terminal/${id}`
});

const add = (data: QmsInspectionTerminal): Promise<QmsInspectionTerminal> =>
  apiClient.post({
    url: "/qms/terminal",
    data
});

const update = (data: QmsInspectionTerminal): Promise<QmsInspectionTerminal> =>
  apiClient.put({
    url: "/qms/terminal",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/qms/terminal",
    params: {
    ids: ids.join(",")
  }
});
const getItems = (id: React.Key): Promise<QmsInspectionTerminalItem[]> =>
  apiClient.get({
    url: `/qms/terminal/item/list/${id}`
  });

export const qmsInspectionTerminalService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getItems,
};

export default qmsInspectionTerminalService;